package com.zhang.yygh.hosp.controller.user;

import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.zhang.yygh.common.result.R;
import com.zhang.yygh.hosp.service.DepartmentService;
import com.zhang.yygh.hosp.service.HospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "医院显示接口")
@RestController
@RequestMapping("/user/hosp/hospital")
public class UserHospitalController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    //根据医院编号hoscode查询医院详细信息
    @ApiOperation(value = "根据医院编号，查询医院信息")
    @GetMapping("/info/{hoscode}")
    public R info(@PathVariable(value = "hoscode") String hoscode){
        Hospital byHoscode = hospitalService.findByHoscode(hoscode);
        return R.ok().data("hospital",byHoscode);
    }

    //根据医院编号hoscode查询医院科室信息
    @GetMapping("/getDeptList/{hoscode}")
    public R getDeptListByHoscode(@PathVariable String hoscode){
        List<DepartmentVo> departmentList = departmentService.getDepartmentList(hoscode);
        return R.ok().data("list",departmentList);
    }

    @ApiOperation(value = "获取分页列表")
    @GetMapping("/{pageNum}/{pageSize}")
    public R getHospitalPage(@PathVariable Integer pageNum,
                             @PathVariable Integer pageSize,
                             HospitalQueryVo hospitalQueryVo){
        Page<Hospital> page=hospitalService.getHospitalPage(pageNum,pageSize,hospitalQueryVo);
        return R.ok().data("pages",page);
    }

    @ApiOperation(value = "根据医院名字进行模糊查询")
    @GetMapping("/findByName/{name}")
    public R findByName(@PathVariable String name){
        List<Hospital> hospitalList=hospitalService.findByName(name);
        return R.ok().data("list",hospitalList);
    }

}
